package com.vitabuybuy.tv.ui.mine.follow.viewmodel

import androidx.lifecycle.MutableLiveData
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.toast.XToast
import com.vitabuybuy.tv.dto.MyFollowListDto
import com.vitabuybuy.tv.network.MineRepository
import com.vitabuybuy.tv.network.StoreRepository

class MyFollowViewModel : BaseViewModel() {

    val followlist = MutableLiveData<MutableList<MyFollowListDto>>()

    fun getMyFollowList(type: String, pageNumber: Int) {
        rxHttpRequest {
            onRequest = {
                val it = MineRepository.getMyFollowList(type, pageNumber, 10) .await()
                followlist.value = it
                defUI.msgEvent.postValue(MessageModel(1, arg1 = it.size))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isLoadingType = true
            isRefresh = pageNumber == 1
        }
    }

    fun collectOrcancel(id: Int, position: Int, isFav: Boolean) {
        rxHttpRequest {
            onRequest = {
                StoreRepository.collectOrcancelStore(id, isFav).await()
                defUI.msgEvent.postValue(MessageModel(2, arg1 = position))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
    fun collectOrcancelExecutor(id: Int, position: Int, isFav: Boolean) {
        rxHttpRequest {
            onRequest = {
                StoreRepository.collectOrcancelExecutor(id, isFav).await()
                defUI.msgEvent.postValue(MessageModel(2, arg1 = position))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
}
